<template>
  <view class="container">
    <image src="/static/images/wx-login.jpeg"></image>
    <view>申请获取以下权限</view>
    <view>获得你的公开信息(昵称，头像、地区等)</view>
    <view>获得你微信绑定的手机号</view>

    <u-button type="primary" size="default" class="login-btn" @tap="login">
      微信授权登录
    </u-button>
  </view>
</template>

<script>
let that;

export default {
  data() {
    return {
    }
  },
  onLoad(option) {
    that = this;
    let token = option.token;
    if (that.$validator.isNotEmpty(token)) {
      // 登录成功回调
      uni.setStorageSync(that.$config.cachePrefix + 'token', token);
      uni.$u.http.get('/au/weiXin/getInfo').then(res => {
        uni.setStorageSync(that.$config.cachePrefix + 'user', res.user);
        uni.setStorageSync(that.$config.cachePrefix + 'role', res.role);
        uni.setStorageSync(that.$config.cachePrefix + 'permissions', res.permissions);
      });
    }
  },
  methods: {
    login() {
      uni.$u.http.get('/au/weiXin/login').then(res => {
        if (res.code == 200) {
          window.location.href = res.data;
        } else {
          that.$msg(res.msg);
        }
      });
    }
  },
}
</script>

<style lang="scss" scoped>
page {
  background-color: white;
}

.container {
  font-size: 13px;
  color: $u-main-color;
  line-height: 25px;
  padding: 100px 20px;
  height: 100vh;

  image {
    width: 60px;
    height: 50px;
    margin-left: calc((100% - 60px) / 2);
  }

  .login-btn {
    margin-top: 50px;
  }
}
</style>

